package com.baozhun.mall.common.adapter

import com.baozhun.mall.common.BR
import com.baozhun.mall.common.R
import com.baozhun.mall.common.base.BaseListAdapter
import com.baozhun.mall.common.databinding.ItemCommonGoodsSelfBinding
import com.baozhun.mall.common.model.bean.GoodsInfoBean
import com.chad.library.adapter.base.listener.OnItemClickListener
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder


/**
 * @Title：通用自营（一行一个）商品配置器
 * @Description：
 * @Author：xing.luo
 * @Since：2022/11/10
 * @Version：1.0.0
 */
class CommonGoodsSelfAdapter(
    data: MutableList<GoodsInfoBean>?,
    private var swipeEnable: Boolean = false,
    private var onItemClickListener: OnItemClickListener? = null
) : BaseListAdapter<GoodsInfoBean, ItemCommonGoodsSelfBinding>(R.layout.item_common_goods_self, data) {

    override fun convert(
        holder: BaseDataBindingHolder<ItemCommonGoodsSelfBinding>, item: GoodsInfoBean
    ) {
        super.convert(holder, item)
        holder.dataBinding?.setVariable(BR.model, item)
        holder.dataBinding?.swipeLayout?.isSwipeEnable = swipeEnable
        holder.dataBinding?.contentView?.setOnClickListener {
            onItemClickListener?.onItemClick(this, holder.dataBinding?.swipeLayout!!, holder.adapterPosition)
        }
        holder.dataBinding?.executePendingBindings()
    }

}